// @Description
// @Author  xiaoyang
// @Date  2023/4/27 2:44 下午

package middles

import (
	"github.com/gin-gonic/gin"
	systemControllers "golang-manage-admin/http/modules/system/controllers"
	"golang-manage-admin/providers"
)

// RecoveryMiddleware
// @Description:  捕捉Panic，返回错误信息
// @Author yang 2025-11-26 17:58:28
// @Return gin.HandlerFunc
func RecoveryMiddleware() gin.HandlerFunc {
	controller := systemControllers.Controller{}
	return func(c *gin.Context) {
		defer func() {
			if err := recover(); err != nil {
				// 写日志
				_ = providers.Logger.Error("系统异常：", err)
				controller.BadResponse(10000, err.(string), c)
				return
			}
		}()
		c.Next()
	}
}
